Examples¶

In [1]:
from package.abn_mir_plotting_functions import figure_3_5
from package.abn_mir_helper_functions import *
from package.bn_graph_methods import *
from package.plotting import *
# from package.plotting import hamming_plots, plot_hamming_transitions
In [2]:
net = select_network(20, 20, 30, 15, 30, 2000)[0]
net.add_cycles(1000)
print(net)
net.compute_unit_perturbations_matrix(0, False)
a_net = AbundantBooleanNetwork(1, [i for i in range(16)], 2, 400, 0)
a_net.from_boolean_network(net)
a_net.add_abundant_nodes(45)
# a_net.add_nested_nodes(16, 32, False, 64, True)
# print(a_net)
setup_colors = get_colors(len(net.bn_collapsed_cycles) + 20, shuffled_if_true=True)
h_s = HammingSetup(net)
BooleanNetwork: N=20. avg_k= 1.6. Run-ins: 1202. Observed cycles: 21. t_records: 1202. u_records: 0
Cycle lengths: [28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 4, 2, 2, 28]

Boolean states over transitions as colormapped values¶

In [3]:
fig, ax = plt.subplots()
run_in = SystemRandom().randrange(0, len(net.list_of_all_run_ins))
plt.text(0, -4, f"steps of {get_ordinal_string(run_in, True)} run-in: ")
plt.imshow(np.transpose(net.list_of_all_run_ins[run_in]), cmap="binary")  # was "gist_stern"
plt.yticks(
    ticks=[i for i in range(len(net))],
    labels=["node " + str(i + 1) for i in range(len(net))],
)
fig.set_size_inches(12, 12)
ax.tick_params(top=True, labeltop=True, bottom=False, labelbottom=False)
i = 0
while not np.allclose(
    net.list_of_all_run_ins[run_in][i], net.list_of_all_run_ins[run_in][-1]
):
    i += 1
ax.hlines(
    -1,
    i,
    ax.get_xlim()[1],
    label=f"cycle {net.bn_collapsed_cycles.get_index(net.list_of_all_run_ins[run_in][-1])}",
)
plt.legend(loc="upper right")
plt.show()
No description has been provided for this image

Polar plot of cycles where radius is Hamming distance to the consensus sequence of all cycle states¶

Cycle states are "aligned" such that the first cycle state is that with the minimum distance to the consensus sequence of all observed cycle states.

In [4]:
plot_polar_cycles_cons_hamm(net, plot_one_period_if_true=True, bv_colors=setup_colors)
plot_polar_cycles_cons_hamm(net, plot_one_period_if_true=False, bv_colors=setup_colors)
Radius: Hamming distance to consensus of cycle states
Theta: varied: 1 step == 2 * Pi / (cycle length)
No description has been provided for this image
Radius: Hamming distance to consensus of cycle states
Theta: 1 step == 0.2243994752564138 radians
No description has been provided for this image
Polar plot of cycles with radius equal to the number of changed node states per step¶
In [5]:
plot_polar_cycles_bv(net, plot_one_period_if_true=True, bv_colors=setup_colors)
plot_polar_cycles_bv(net, plot_one_period_if_true=False, bv_colors=setup_colors)
Radius: step to step edit-distance
Assuming each cycle is 24 hours, 1 step == [51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 51.42857142857143, 360.0, 720.0, 720.0, 51.42857142857143] minutes
No description has been provided for this image
Radius: step to step edit-distance
Theta: 1 step == 0.2243994752564138 radians
least common multiple: 28
No description has been provided for this image

Plotting cycles and transitions in arbitrary Hamming distance space¶

In [6]:
hamm_seq = HammingSetup(net)
hamming_plots(net, hamm_seq, bv_colors=setup_colors)
2D plot of observed cycles, and homogeneous conditions

Equilibrial states are represented as a +, and non-equilibrial states are represented by a points connected by a dotted line
If lines appear solid, this is because a dotted line going to and from a point overlap in such a way as to appear solid.

Axis 1 (x): a linear combination of the Hamming distances to a first set of sequences 
(the consensus of the most-observed cycle, and 15 random sequences).
Axis 2 (y): a linear combination of the Hamming distance to a second set of sequences 
(all False, and 15 random sequences).

Weights of Hamming distances: [1, 0.3679, 0.2707, 0.1991, 0.1465, 0.0539, 0.0397, 0.0292, 0.0215, 0.0158, 0.0116, 0.01, 0.01, 0.01, 0.01, 0.01]

No description has been provided for this image
No description has been provided for this image

Transitions over unit perturbations to all cycle states¶

In [7]:
transitions(net)
Transitions resulting from unit perturbations of all observed cycle states of BooleanNetwork: N=20. avg_k= 1.6. Run-ins: 1202. Observed cycles: 21. t_records: 1202. u_records: 0
Cycle lengths: [28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 4, 2, 2]
Number of cycle perturbations records: 10240 == 512 * 20(= sum(length of all cycles) * number of nodes)

The row represents the starting cycle index

The column represents the ending cycle index

        |     0      1      2      3      4      5      6      7      8      9     10     11     12     13     14     15     16     17     18     19     20    None  
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
  0     |    268     0     59      0      0      0      0      0      0     75     21     28      0      0     58     51      0      0      0      0      0      0   
  1     |     0     289     0     40      0      9     78      1     10      0     28     11     49     45      0      0      0      0      0      0      0      0   
  2     |    73      0     127     0     43      0      0      0      0     57     59      0      0     28     60     61     47      5      0      0      0      0   
  3     |     0     43      0     218    28      6      5     86     81      0      0      1     46     45      0      0      0      0      1      0      0      0   
  4     |     6      0     61     28     130     0      0      0      0     24     56      0      0      0      9     59     88     98      0      0      0      1   
  5     |     0      9      0      4      0     219     6     80     39     28      0     84     44     47      0      0      0      0      0      0      0      0   
  6     |     0     79      0      5      0      6     214    75     10      0      0     51     47     45     28      0      0      0      0      0      0      0   
  7     |     0      2      0     88      0     86     79     213    11      0      0      2      7      7      0      0      0     28     37      0      0      0   
  8     |     0     10      0     79      0     42     11     12     288     0      0      0     42     44      0      0     28      0      4      0      0      0   
  9     |    114     0     60      0     13     28      0      0      0     136    13      0      0      0     23     50     40     83      0      0      0      0   
  10    |    35     28     51      0     36      0      0      0      0     14     218     0      0      0     84     73     20      1      0      0      0      0   
  11    |    28      9      0      0      0     77     48      0      0      0      0     307    45     46      0      0      0      0      0      0      0      0   
  12    |     0     46      0     42      0     46     46      5     41      0      0     48     211    47      0     28      0      0      0      0      0      0   
  13    |     0     46     28     43      0     45     46      5     41      0      0     49     46     211     0      0      0      0      0      0      0      0   
  14    |    70      0     50      0      9      0     28      0      0     26     88      0      0      0     144    62     15     68      0      0      0      0   
  15    |    73      0     61      0     43      0      0      0      0     57     59      0     28      0     60     127    47      5      0      0      0      0   
  16    |     0      0     69      0     86      0      0      0     28     63     18      0      0      0     19     55     197    21      0      0      0      4   
  17    |    11      0     16      0     99      0      0     28      0     105     6      0      0      0     89     16     16     140     0      0      0     34   
  18    |     0      0      0      2      0      1      0     40      4      0      0      0      0      0      0      0      0      0     29      0      0      4   
  19    |     2      1      0      0      0      0      0      0      0      0      0      5      1     13      0      0      0      0      0     18      0      0   
  20    |     2      0      0      0      0      1      0      0      0      0      0      9      0      4      0      0      0      0      0      5     19      0   
 None   |     0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0   


Transitions resulting from unit perturbations of all observed states of BooleanNetwork: N=20. avg_k= 1.6. Run-ins: 1202. Observed cycles: 21. t_records: 1202. u_records: 0
Cycle lengths: [28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 4, 2, 2]
Number of perturbations records: 10240 == (number of states in run-ins without a cycle + number of states with an index of None in run-ins with a cycle + number of cycle states) * number of nodes

The row represents the starting cycle index

The column represents the ending cycle index

        |     0      1      2      3      4      5      6      7      8      9     10     11     12     13     14     15     16     17     18     19     20    None  
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
  0     |    268     0     59      0      0      0      0      0      0     75     21     28      0      0     58     51      0      0      0      0      0      0   
  1     |     0     289     0     40      0      9     78      1     10      0     28     11     49     45      0      0      0      0      0      0      0      0   
  2     |    73      0     127     0     43      0      0      0      0     57     59      0      0     28     60     61     47      5      0      0      0      0   
  3     |     0     43      0     218    28      6      5     86     81      0      0      1     46     45      0      0      0      0      1      0      0      0   
  4     |     6      0     61     28     130     0      0      0      0     24     56      0      0      0      9     59     88     98      0      0      0      1   
  5     |     0      9      0      4      0     219     6     80     39     28      0     84     44     47      0      0      0      0      0      0      0      0   
  6     |     0     79      0      5      0      6     214    75     10      0      0     51     47     45     28      0      0      0      0      0      0      0   
  7     |     0      2      0     88      0     86     79     213    11      0      0      2      7      7      0      0      0     28     37      0      0      0   
  8     |     0     10      0     79      0     42     11     12     288     0      0      0     42     44      0      0     28      0      4      0      0      0   
  9     |    114     0     60      0     13     28      0      0      0     136    13      0      0      0     23     50     40     83      0      0      0      0   
  10    |    35     28     51      0     36      0      0      0      0     14     218     0      0      0     84     73     20      1      0      0      0      0   
  11    |    28      9      0      0      0     77     48      0      0      0      0     307    45     46      0      0      0      0      0      0      0      0   
  12    |     0     46      0     42      0     46     46      5     41      0      0     48     211    47      0     28      0      0      0      0      0      0   
  13    |     0     46     28     43      0     45     46      5     41      0      0     49     46     211     0      0      0      0      0      0      0      0   
  14    |    70      0     50      0      9      0     28      0      0     26     88      0      0      0     144    62     15     68      0      0      0      0   
  15    |    73      0     61      0     43      0      0      0      0     57     59      0     28      0     60     127    47      5      0      0      0      0   
  16    |     0      0     69      0     86      0      0      0     28     63     18      0      0      0     19     55     197    21      0      0      0      4   
  17    |    11      0     16      0     99      0      0     28      0     105     6      0      0      0     89     16     16     140     0      0      0     34   
  18    |     0      0      0      2      0      1      0     40      4      0      0      0      0      0      0      0      0      0     29      0      0      4   
  19    |     2      1      0      0      0      0      0      0      0      0      0      5      1     13      0      0      0      0      0     18      0      0   
  20    |     2      0      0      0      0      1      0      0      0      0      0      9      0      4      0      0      0      0      0      5     19      0   
 None   |     0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0      0   
Transitions in same Hamming space as above¶
In [8]:
figure_3_5(net, hamm_seq, bv_colors=setup_colors)
Figure 2.1: A transition from calculation of unit perturbations, as text output, and in the same Hamming space as above:

cycle index:      0         None        None        None         10     

     node 1:      0     -     0          1          0          1     
     node 2:      1     -     1          1          0          0     
     node 3:      1     -     1          1          1          1     
     node 4:      0     -     1          0          0          0     
     node 5:      0     -     0          1          1          1     
     node 6:      0     -     0          0          1          1     
     node 7:      0     -     0          1          1          1     
     node 8:      0     -     0          0          0          1     
     node 9:      1     -     1          1          1          1     
    node 10:      1     -     1          0          1          0     
    node 11:      0     -     0          1          0          1     
    node 12:      0     -     0          0          0          0     
    node 13:      0     -     0          0          0          0     
    node 14:      0     -     0          1          0          1     
    node 15:      1     -     1          1          1          1     
    node 16:      1     -     1          1          0          1     
    node 17:      1     -     1          1          1          1     
    node 18:      1     -     1          1          0          0     
    node 19:      0     -     0          1          0          0     
    node 20:      1     -     1          1          1          1     
No description has been provided for this image
Figure 2.2: 9 transitions from calculation of unit perturbations in the same Hamming space as above:
1 of 49 transitions from cycle 1 to cycle 12
No description has been provided for this image
1 of 73 transitions from cycle 2 to cycle 0
No description has been provided for this image
1 of 46 transitions from cycle 3 to cycle 12
No description has been provided for this image
1 of 61 transitions from cycle 4 to cycle 2
No description has been provided for this image
1 of 4 transitions from cycle 5 to cycle 3
No description has been provided for this image
1 of 47 transitions from cycle 6 to cycle 12
No description has been provided for this image
1 of 88 transitions from cycle 7 to cycle 3
No description has been provided for this image
1 of 79 transitions from cycle 8 to cycle 3
No description has been provided for this image
1 of 13 transitions from cycle 9 to cycle 4
No description has been provided for this image
Figure 2.3: All transitions between two cycles, in the same Hamming space as set in Hamming setup
from cycle A to cycle B
No description has been provided for this image
from cycle B to cycle A
No description has been provided for this image

Graph representations of network¶

In [9]:
fig = get_graph_representation(net)
fig.set_size_inches(w=12, h=12)
plt.show()
No description has been provided for this image
In [10]:
# make fig
# define function that modifies the fig
# call function after each add_cycle;
# import matplotlib.pyplot as plt  # TODO regarding updated_trajectories function

Abundances as a function of Boolean states¶

In [11]:
for c in a_net.bn_collapsed_cycles.cycle_records:
    a_net.animate_boolean_states_list(c.cycle_states_list, 5, True)
    plot_abundances(
        a_net.current_abundances_list,
        f"Cycle {a_net.bn_collapsed_cycles.get_index(c.cycle_states_list[0])}",
        setup_colors,
        True,
        [],
        None,
        None,
        [12, 6],
        [],
    )
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image